package de.revdev.streckenliste.entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

/**
 *
 * @author f.lindermaier
 */
@Entity
@Table(name = "tbl_Revier")
public class Revier implements Serializable {

    public enum RevierArt {

        ERev, SRev, GRev
    }
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "idRevier")
    private Long id;
    @NotNull
    @Size(min = 1, max = 50)
    private String revierName;
    @NotNull
    @Enumerated(EnumType.STRING)
    private RevierArt revierArt;
    private String amtlSchlNrGem;
    private String nrRevLst;
    @ManyToOne
    private Benutzer jaeger;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "revier")
    private List<Streckenliste> streckenListen;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "revier")
    private List<Abschussplan> abschussplaene;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public RevierArt getRevierArt() {
        return revierArt;
    }

    public void setRevierArt(RevierArt revierArt) {
        this.revierArt = revierArt;
    }

    public String getRevierName() {
        return revierName;
    }

    public void setRevierName(String revierName) {
        this.revierName = revierName;
    }

    public String getAmtlSchlNrGem() {
        return amtlSchlNrGem;
    }

    public void setAmtlSchlNrGem(String amtlSchlNrGem) {
        this.amtlSchlNrGem = amtlSchlNrGem;
    }

    public Benutzer getJaeger() {
        return jaeger;
    }

    public void setJaeger(Benutzer jaeger) {
        this.jaeger = jaeger;
    }

    public String getNrRevLst() {
        return nrRevLst;
    }

    public void setNrRevLst(String nrRevLst) {
        this.nrRevLst = nrRevLst;
    }

    public List<Streckenliste> getStreckenListen() {
        return streckenListen;
    }

    public void setStreckenListen(List<Streckenliste> streckenListen) {
        this.streckenListen = streckenListen;
    }

    public List<Abschussplan> getAbschussplaene() {
        return abschussplaene;
    }

    public void setAbschussplaene(List<Abschussplan> abschussplaene) {
        this.abschussplaene = abschussplaene;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Revier)) {
            return false;
        }
        Revier other = (Revier) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "de.revdev.strevkenliste.entities.Revier[ id=" + id + " ]";
    }

    public String holeRevArt() {
        if (revierArt.equals(RevierArt.ERev)) {
            return "Eigenjagdrevier";
        } else if (revierArt.equals(RevierArt.GRev)) {
            return "Gemeinschaftsjagdrevier";
        } else {
            return "Staatsjagdrevier";
        }
    }
}